package com.ccx.demo.Controller.RoleController;

import com.ccx.demo.Vo.Result;
import com.ccx.demo.Vo.ResultService;
import com.ccx.demo.pojo.SysRole;
import com.ccx.demo.service.RoleService;
import com.ccx.demo.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class RoleController {

    @Autowired
    private ResultService resultService;

    @Autowired
    private SysUserService sysUserService;

    @Autowired
    private RoleService roleService;

    @GetMapping("/QueryRole")
    public Result QueryRole(){
        List<SysRole> sysRoles = sysUserService.QueryByRole();
        return resultService.OK(sysRoles);
    }
    @GetMapping("/QueryRoleById")
    public Result QueryRoleById(Integer userId){
        SysRole sysRole = sysUserService.SelectRole(userId);
        return resultService.OK(sysRole);
    }

    /**
     * 修改角色
     */
    @PutMapping("/UpRoleCode")
    public Result UpRoleCode( Integer code,  Integer userId){
        System.out.println(code+"===="+userId);
        boolean b = roleService.UpRoleCode(code, userId);
        if (b){
            return resultService.OK(b);
        }else{
            return resultService.FAIL();
        }
    }
}
